package com.xpgk.mvc.outPersonnel;

import java.util.HashMap;
import java.util.Map;

import com.jfinal.log.Log;
import com.xpgk.annotation.Service;
import com.xpgk.constant.ConstantRender;
import com.xpgk.dto.RenderBean;
import com.xpgk.mvc.base.BaseService;
import com.xpgk.mvc.intoPersonnel.IntoPersonnel;
import com.xpgk.mvc.intoPersonnel.IntoPersonnelServices;

@Service(name = OutPersonnelServices.serviceName)
public class OutPersonnelServices extends BaseService{

	public static final String serviceName = "outPersonnelServices";
	private static final Log log = Log.getLog(OutPersonnelServices.class);
	
	/**
	 * 保存员工登记信息
	 * */
	public RenderBean  saveOutPer(OutPersonnel outPersonnel,String personnelIds,String orgids)
	{
			
	
		RenderBean result = new RenderBean();
		String  msg="";
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("column", OutPersonnel.column_userIds);
		String sql = getSqlByBeetl(OutPersonnel.sqlId_column, param);
		OutPersonnel personnel = OutPersonnel.dao.findFirst(sql, outPersonnel.getStr(OutPersonnel.column_userIds));
		if(personnel!=null)
		{
			personnel.set(OutPersonnel.column_entrytime, outPersonnel.getDate(OutPersonnel.column_entrytime))
			.set(OutPersonnel.column_dimissiontime, outPersonnel.getDate(OutPersonnel.column_dimissiontime))
			.set(OutPersonnel.column_dimissionReason, outPersonnel.getStr(OutPersonnel.column_dimissionReason))
			.set(OutPersonnel.column_position_goods_delivery, outPersonnel.getStr(OutPersonnel.column_position_goods_delivery))
			.set(OutPersonnel.column_position_goods_handover, outPersonnel.getStr(OutPersonnel.column_position_goods_handover))
			.set(OutPersonnel.column_position_goods_to_handover, outPersonnel.getStr(OutPersonnel.column_position_goods_to_handover))
			.set(OutPersonnel.column_position_work_delivery, outPersonnel.getStr(OutPersonnel.column_position_work_delivery))
			.set(OutPersonnel.column_position_work_handover, outPersonnel.getStr(OutPersonnel.column_position_work_handover))
			.set(OutPersonnel.column_position_work_to_handover, outPersonnel.getStr(OutPersonnel.column_position_work_to_handover))
			.set(OutPersonnel.column_personnel_key_delivery, outPersonnel.getStr(OutPersonnel.column_personnel_key_delivery))
			.set(OutPersonnel.column_personnel_key_handover, outPersonnel.getStr(OutPersonnel.column_personnel_key_handover))
			.set(OutPersonnel.column_personnel_key_to_handover, outPersonnel.getStr(OutPersonnel.column_personnel_key_to_handover))
			.set(OutPersonnel.column_personnel_attendance_day, outPersonnel.getInt(OutPersonnel.column_personnel_attendance_day))
			.set(OutPersonnel.column_personnel_leave_days, outPersonnel.getInt(OutPersonnel.column_personnel_leave_days))
			.set(OutPersonnel.column_personnel_other, outPersonnel.getStr(OutPersonnel.column_personnel_other))
			.set(OutPersonnel.column_financial_borrowing_settlement, outPersonnel.getStr(OutPersonnel.column_financial_borrowing_settlement))
			.set(OutPersonnel.column_financial_salary_settlement, outPersonnel.getStr(OutPersonnel.column_financial_salary_settlement))
			.set(OutPersonnel.column_financial_other, outPersonnel.getStr(OutPersonnel.column_financial_other))
			.set(OutPersonnel.column_cashier_signature, outPersonnel.getStr(OutPersonnel.column_cashier_signature))
			.set(OutPersonnel.column_employer_opinion, outPersonnel.getStr(OutPersonnel.column_employer_opinion))
			.set(OutPersonnel.column_personnel_department_opinion, outPersonnel.getStr(OutPersonnel.column_personnel_department_opinion))
			.set(OutPersonnel.column_vice_president_opinion, outPersonnel.getStr(OutPersonnel.column_vice_president_opinion))
			.set(OutPersonnel.column_president_opinion, outPersonnel.getStr(OutPersonnel.column_president_opinion));
			
			 
			if(!personnel.update())
			{
				log.debug("更新员工离职信息失败");
				throw new RuntimeException("更新员工离职信息失败!");
			}
			
		
			msg=ConstantRender.render_success_code;
			result.getMap().put("msg", msg);
//			result.getMap().put("customerIds", cc.getStr(Customer.column_ids));
		}else
		{
			if(outPersonnel.save()){
				
				System.out.println("添加成功");
				msg=ConstantRender.render_success_code;
			
					}else{
				System.out.println("shibai ");
				msg="添加失败！";
			}
			result.getMap().put("msg", msg);
			return result;
		}
		result.getMap().put("msg", msg);
		return result;
	}
	
}
